# 初学python练习
# 姓 名：张宇
# 开发时间：2024/07/26 19:47
import re
import requests

url = "https://www.22shuquge.net/b/568/568620/142488950.html"
head = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
    }
repo = requests.get(url,headers=head)
repo.encoding = "utf-8"

obj = re.compile(r'<div class="content" id="content">.*?'
                 r'<p>(?P<name>.*?)</p>.*?'
                 r'<p>(?P<context>.*)</p>.*?记住本站最新地址.*?'
                 r'<a id="next_url" href="(?P<next>.*?)"> 下一页</a>.*?'

                ,re.S)
# r'<p>(?P<context>.*)</p>.*?'
# r'</div><a href="/" class="btn-addbs">『记住本站最新地址   www.22shuquge.com』</a>'
finditer = obj.finditer(repo.text)

for item in finditer:
    dict = item.groupdict()
    dict["context"]=dict["context"].replace("</p><p>","")
    print(dict)
# print(finditer)
# print(repo.text)
# print(repo.request.headers)

